package com.aSemy.qotwReader.core.utils;

import java.io.File;

import com.aSemy.qotwReader.core.question.QuestionData;
import com.aSemy.qotwReader.core.types.EbookType;
import com.aSemy.qotwReader.core.types.ReaderType;


/**
 * Methods for creating valid filenames for saving questions.
 * @author Adam Semenenko
 */
public abstract class Filenames
{
    /** b3ta's full web address*/
    public static final String b3taAddress = "http://www.b3ta.com";
    
    /**
     * Gives a filename used to save a question to an ebook.
     * Removes any non-alphabetic characters to ensure that no special characters
     * reserved by the operating system are used.
     * 
     * Ebooks are saved in the format [title]_[date].[ebook] in a folder detemined by {@link #getDirName(EbookType, ReaderType)}.
     * 
     * @param ebook The type of ebook to save.
     * @param data The object containing information specific to the book, such as title, data, etc
     * @return The filename the ebook should be saved as.
     */
    public static String getFilename(EbookType ebook, QuestionData data)
    {
        return 
            getDirName(ebook, data.getReaderType())
            + (data.getFilesafeTitle() + "_" + data.getFilesafeDate()).replaceAll("\\W", "_")
            + "."
            + ebook.toString();
    }
    
    /**
     * Get the directory the ebook should saved as.
     * 
     * Since questions are saved with the same name we need to separate them based on format/ebook reader.
     * So we save them in different folders.
     * 
     * Folders are of the format [ebooktype]_[readertype]/
     * 
     * @param ebook The type of ebook being saved
     * @param reader The reader type the ebook is tailored for
     * @return A relative directory name.
     */
    private static String getDirName(EbookType ebook, ReaderType reader)
    {
        return ebook.toString() + "_ " + reader.toString() + File.separator;
    }
}
